<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-steps :active="step" align-center class="steps" finish-status="success">
          <el-step title="待归还样本"></el-step>
          <el-step title="分配位置"></el-step>
          <el-step title="提交申请"></el-step>
          <el-step title="完成"></el-step>
        </el-steps>
      </el-col>
      <el-col v-show="step==0" :span="24">
        <el-card class="box-card">
          <el-row :gutter="10" align="middle" class="mb8" type="flex">
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:stockReturn:query']"
                icon="el-icon-plus"
                plain
                size="mini"
                type="primary"
                @click="handlePick"
              >未归还样本
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:stockReturn:edit']"
                :disabled="multiple"
                icon="el-icon-remove-outline"
                plain
                size="mini"
                type="success"
                @click="handleRemove"
              >批量移除
              </el-button>
            </el-col>
            <el-col :span="2.5">
              <el-input v-model="qrCode" v-hasPermi="['biobank:stockReturn:query']" clearable placeholder="添加归还样本"
                        size="small" @change="qrCodeChangeEvent"
              >
                <template slot="prepend">扫描条码</template>
              </el-input>
            </el-col>
            <el-col :span="1.5">
              <el-select v-model="queryParams.own" placeholder="请选择" size="small" @change="ownChange">
                <el-option
                  v-for="item in ownOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>

          <el-table v-loading="loading" :data="sampleList" max-height="650" @selection-change="handleSelectionChange">
            <el-table-column align="center" type="selection" width="55"/>
            <el-table-column align="center" label="样本复份编号" min-width="110" prop="sampBackupCode"/>
            <el-table-column align="center" label="样本类型" prop="sampTypeName"/>
            <el-table-column align="center" label="样本源编号" prop="sampSourceCode"/>
            <el-table-column align="center" label="样本源名称" prop="sampSourceName"/>
            <el-table-column align="center" label="采样时间" prop="samplingTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.samplingTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本源类型" prop="sampSourceTypeName"/>
            <el-table-column align="center" label="样本组" prop="sampGroupName"/>
            <el-table-column align="center" label="样本量" prop="sampQuantity">
              <template slot-scope="scope">
                <el-input v-show="scope.row.editShow" v-model="scope.row.sampQuantity"
                          oninput="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入样本量" size="small"
                ></el-input>
                <span v-show="!scope.row.editShow">{{ scope.row.sampQuantity }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本单位" prop="sampUnit"/>
            <el-table-column :formatter="sampStateFormat" align="center" label="样本状态" prop="sampState"/>
            <el-table-column align="center" label="条码/二维码" prop="qrCode"/>
            <el-table-column align="center" label="操作" width="180">
              <template slot-scope="scope">
                <div v-show="!scope.row.editShow">
                  <el-button v-hasPermi="['biobank:stockReturn:edit']" icon="el-icon-edit" size="mini" type="text"
                             @click="handleEdit(scope.$index, scope.row)"
                  >编辑
                  </el-button>
                  <el-button v-hasPermi="['biobank:stockReturn:edit']" icon="el-icon-delete" size="mini" type="text"
                             @click="handleRemove(scope.row)"
                  >移除
                  </el-button>
                </div>
                <div v-show="scope.row.editShow">
                  <el-button icon="el-icon-close" size="mini" type="text"
                             @click="handleCancel(scope.$index, scope.row)"
                  >取消
                  </el-button>
                  <el-button icon="el-icon-check" size="mini" type="text" @click="handleSave(scope.$index, scope.row)">
                    保存
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total>0"
            :limit.sync="queryParams.pageSize"
            :page.sync="queryParams.pageNum"
            :total="total"
            @pagination="getList"
          />
        </el-card>
        <el-button v-hasPermi="['biobank:stockReturn:edit']" class="bottom-btn" type="success" @click="assignLocation">
          下一步：分配位置
        </el-button>
      </el-col>
      <el-col v-show="step==1" :span="24">
        <el-card class="box-card">
          <!-- 分配位置 -->
          <el-row>
            <el-col :span="13">
              <el-table ref="virtualTable" :data="selectSamples" max-height="690"
                        @selection-change="virtualSelectionChange"
              >
                <el-table-column align="center" type="selection" width="55"/>
                <el-table-column align="center" label="样本复份编号" prop="sampBackupCode"/>
                <el-table-column align="center" label="样本源名称" prop="sampSourceName"/>
                <el-table-column align="center" label="样本源类型" prop="sampSourceTypeName"/>
                <el-table-column align="center" label="样本组" prop="sampGroupName"/>
                <el-table-column align="center" label="样本位置" prop="sampLocation" width="240"/>
                <el-table-column align="center" label="条码/二维码" prop="qrCode"/>
              </el-table>
            </el-col>

            <el-col :span="11">
              <el-row :gutter="10" class="mb8" style="margin-left: 16px">
                <el-col :span="1.5">
                  <el-button icon="el-icon-aim" plain size="mini" type="primary" @click="virtualSelectBox">选择冻存盒
                  </el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button icon="el-icon-check" plain size="mini" type="success" @click="virtualConfirmLoc">确认样本位置
                  </el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button icon="el-icon-refresh" plain size="mini" type="warning" @click="virtualClearLoc">清空样本位置
                  </el-button>
                </el-col>
              </el-row>

              <div v-if="selectContainer && Object.keys(selectContainer).length != 0">
                <span style="margin-left: 21px; font-size: 14px">{{ selectContainer.containerLocation }}</span>
                <el-button icon="el-icon-close" size="mini" style="padding-left: 16px" type="text"
                           @click="virtualDelBox"
                >删除冻存盒
                </el-button>
              </div>
              <el-table v-if="selectTubes && selectTubes.length > 0" :key="tubeTableKey" :data="selectTubes"
                        :row-style="{'height': 540/selectContainer.boxRow + 'px'}" border class="customer-table"
                        height="590px" style="margin-left: 21px; margin-top: 10px; width: 583px"
                        @cell-click="tableCellClick"
              >
                <el-table-column align="center" type="index" width="42">
                  <template slot-scope="scope">
                    <span>{{ tubeRow[scope.$index] }}</span>
                  </template>
                </el-table-column>
                <el-table-column v-for="(item, index) in selectTubes" :key="index" :label="index + 1 + ''"
                                 :width="540/selectContainer.boxColumn" align="center"
                >
                  <template slot-scope="scope">
                    <el-popover
                      placement="right"
                      trigger="hover"
                      width="230"
                    >
                      <div v-if="scope.row[index].sample">
                        <div>样本状态：{{ sampStateFormat(scope.row[index].sample) }}</div>
                        <div><span>复份编号：{{ scope.row[index].sample.sampBackupCode }}</span></div>
                        <div><span>样本源名称：{{ scope.row[index].sample.sampSourceName }}</span></div>
                        <div><span>样本类型名称：{{ scope.row[index].sample.sampTypeName }}</span></div>
                        <div><span>样本组：{{ scope.row[index].sample.sampGroupName }}</span></div>
                        <div><span>条码/二维码：{{ scope.row[index].sample.qrCode }}</span></div>
                      </div>
                      <svg-icon v-if="scope.row[index].sample"
                                slot="reference"
                                :class="scope.row[index].sample.sampState === '1' ? 'table-icon' : 'table-icon-blur'"
                                :icon-class="scope.row[index].sample.sampTypeIcon"
                      />
                    </el-popover>
                    <svg-icon v-if="scope.row[index].tubeState === '2'" class="table-icon" icon-class="disable"/>
                    <svg-icon v-if="scope.row[index].tubeState === '1'" class="table-icon" icon-class="broken"/>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </el-card>
        <div class="bottom-btn">
          <el-button type="primary" @click="step = 0">上一步</el-button>
          <el-button type="success" @click="step = 2">下一步：提交申请</el-button>
        </div>
      </el-col>
      <el-col v-show="step==2" :span="24">
        <el-card class="box-card">
          <el-input v-model="approveForm.stockTitle" placeholder="请输入单据标题">
            <template slot="prepend">单据标题</template>
          </el-input>
          <editor v-model="approveForm.stockDesc" :min-height="480"/>
          <file-upload :value="approveForm.attaches" style="margin-top: 16px" @fileEvent="fileUploadEvent"
          ></file-upload>
        </el-card>
        <div class="bottom-btn">
          <el-button type="primary" @click="step = 1">上一步</el-button>
          <el-button :loading="applying" type="success" @click="confirmApprove">下一步：完成</el-button>
        </div>
      </el-col>
      <el-col v-show="step==3" :span="24">
        <el-card align="center" class="box-card">
          <h1 style="margin-top: 160px">归还申请成功</h1>
          <el-button type="primary" @click="keepAdd">继续申请</el-button>
        </el-card>
      </el-col>
    </el-row>

    <!-- 挑选样本对话框 -->
    <sample-pick :open="open" :value="sampleList" samp-state="5" @onClose="samplePickClose"
                 @onConfirm="samplePickEvent"
    ></sample-pick>
    <!-- 容器树 对话框 -->
    <el-dialog :visible.sync="treeVisible" append-to-body title="选择冻存盒" width="40%">
      <el-tree
        ref="containerTree"
        :data="containerList"
        :expand-on-click-node="true"
        :highlight-current="highlightCurrent"
        :load="loadLazyTree"
        :props="containerTreeProps"
        lazy
        node-key="containerId"
        style="height: 480px; overflow: auto; min-width: 100%; display: inline-block"
        @node-click="treeNodeClick"
      >
          <span slot-scope="{ node, data }">
            <svg-icon :icon-class="data.containerIcon" style="margin-right: 3px"/>
            <span>{{ node.label }}</span>
            <span :style="judgeColor(data.storageRate)">{{ data.storageRate }}%</span>
          </span>
      </el-tree>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmBoxSelect">确 定</el-button>
        <el-button @click="cancelBoxSelect">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { getSampleByQrCode, listSample, updateSample, updateSamples } from '@/api/biobank/sample'
import Parser from 'form-gen-parser'
import Editor from '@/components/Editor'
import FileUpload from '@/components/FileUpload'
import { lazyTree } from '@/api/biobank/container'
import { clearLocation, confirmLocation, listTube } from '@/api/biobank/tube'
import { addStock } from '@/api/activiti/stock'
import SamplePick from '@/views/biobank/sample/SamplePick'

export default {
  name: 'StockReturn',
  components: {
    Parser,
    Editor,
    FileUpload,
    SamplePick
  },
  data() {
    return {
      step: 0,
      // 遮罩层
      loading: true,
      // 非多个禁用
      multiple: true,
      // 选中数组
      ids: [],
      // 扫码的条码/二维码
      qrCode: undefined,
      // 选中的样本复份
      selectSamples: [],
      // 分配位置 选中的容器盒
      selectContainer: {},
      // 分配位置 选中盒的冻存管
      selectTubes: [],
      // 分配位置 选中的样本复份
      virtualSelectSamples: [],
      // 分配位置 选中单元格的试管
      virtualSelectTube: {},
      // 分配位置 容器树 数据
      containerList: [],
      // 分配位置 前一次选中的cell
      oldSelectTableCell: undefined,
      // 申请单关联的所有样本
      approveSamples: [],
      // 容器树
      containerTreeProps: {
        children: 'children',
        label: 'title',
        isLeaf: 'leaf'
      },
      // 挑选样本对话框
      open: false,
      // 容器树对话框
      treeVisible: false,
      // 容器树是否高亮选中
      highlightCurrent: false,
      // 总条数
      total: 0,
      ownOptions: [
        {
          value: '0',
          label: '我的'
        },
        {
          value: '1',
          label: '所有'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'updateTime',
        isAsc: 'DESC',
        sampState: '7',// 待归还
        stockState: '0',
        own: '0' // 0-我的 1-所有
      },
      // 样本复份 表格数据
      sampleList: [],
      // 提交申请 附件列表
      uploadFileList: [],
      // 审批表单
      approveForm: {},
      // 样本状态
      sampStateOptions: [],
      // 表格行值
      tubeRow: this.GLOBAL.TUBE_ROW,
      // 申请中
      applying: false,
      // 试管table的key 为了data更改后视图更新
      tubeTableKey: 0,
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('sample_state').then(response => {
      this.sampStateOptions = response.data
    })
  },
  methods: {
    // 提交审批
    confirmApprove() {
      if (!this.approveSamples || this.approveSamples.length === 0) {
        this.$message.warning(`请选择要归还的样本`)
        return false
      }
      let allConfirmLoc = true
      this.approveSamples.forEach(s => {
        if (!s.sampLocation || s.sampLocation === '') {
          allConfirmLoc = false
        }
      })
      if (!allConfirmLoc) {
        this.$message.warning(`请先确认要归还的样本位置`)
        return false
      }
      this.approveForm.stockType = this.GLOBAL.STOCK_TYPE.RETURN//"return"
      this.approveForm.sampleBackups = this.approveSamples
      this.approveForm.attaches = this.uploadFileList

      this.applying = true
      addStock(this.approveForm).then(response => {
        this.$message.success(`归还申请提交成功`)
        this.applying = false
        this.step = 3
      }, error => {
        this.applying = false
      })
    },
    // 继续添加 直接刷新页面
    keepAdd() {
      // this.$router.go(0); // 刷新界面
      this.step = 0
      this.$store.dispatch('tagsView/delCachedView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({
            path: '/redirect' + this.$route.fullPath
          })
        })
      })
    },
    // 下一步 分配位置
    assignLocation() {
      if (this.selectSamples.length === 0) {
        this.$message.warning(`请先选择要归还的样本`)
      } else {
        this.step = 1
        this.$set(this.approveForm, 'stockTitle', this.$store.getters.nickName + '的样本归还申请')
      }
    },
    // 分配位置 多选框选中事件
    virtualSelectionChange(selection) {
      this.virtualSelectSamples = selection
      this.virtualSelectSamples.forEach(item => {
        if (item.sampState === this.GLOBAL.SAMPLE.TO_RETURN && this.approveSamples.indexOf(item) === -1 // sampState === '7'
          && item.sampLocation && item.sampLocation !== '') {
          this.approveSamples.push(item)
        }
      })
    },
    // 选择冻存盒 按钮点击事件 -> 弹出树
    virtualSelectBox() {
      this.treeVisible = true
    },
    // 附件上传子组件回调
    fileUploadEvent(fileList) {
      this.uploadFileList = fileList
    },
    // 确认样本位置 按钮点击事件
    virtualConfirmLoc() {
      if (!this.virtualSelectSamples || this.virtualSelectSamples.length === 0) {
        this.$message('请先选择要确认位置的样本')
        return false
      }
      let hasConfirmLocSamp = false
      this.virtualSelectSamples.forEach(item => {
        if (item.sampLocation && item.sampLocation !== '') {
          hasConfirmLocSamp = true
        }
      })
      if (hasConfirmLocSamp) {
        this.$message.warning('当前选中的样本中存在已确认位置的样本，若要重新确认位置请先清空该样本的位置')
        return false
      }
      if (!this.virtualSelectTube || Object.keys(this.virtualSelectTube).length === 0) {
        this.$message('请先选择冻存管位置')
        return false
      }
      // 二维数组转一维数组
      let tubesArray = this.selectTubes.reduce((prev, next) => {
        return prev.concat(next)
      })
      let offset = 0
      tubesArray.forEach((item, index) => {
        let odds = item.tubeSort >= this.virtualSelectTube.tubeSort &&
          (item.sample === undefined || Object.keys(item.sample).length === 0) && offset < this.virtualSelectSamples.length
        if (odds) {
          item.sample = this.virtualSelectSamples[offset]
          this.selectSamples.forEach((sample, i) => {
            if (sample.sampBackupId === this.virtualSelectSamples[offset].sampBackupId) {
              this.virtualSelectSamples[offset].sampLocation = this.selectContainer.containerLocation + '/' + item.tubeLocation
              // 添加进单据关联样本数组
              this.approveSamples.push(this.virtualSelectSamples[offset])
              this.selectSamples.slice(i, 1, this.virtualSelectSamples[offset])
            }
          })
          offset++
          item.sampBackupId = item.sample.sampBackupId
          tubesArray.splice(index, 1, item)
        }
      })
      // 一维数组转二维数组
      this.convertArray(tubesArray)

      // 确认样本位置 成功后清空virtualSelectSamples
      let confirmForm = {}
      confirmForm.sampleBackups = this.virtualSelectSamples
      confirmForm.tubes = tubesArray
      confirmLocation(confirmForm).then(response => {
        this.virtualSelectSamples = []
        this.$refs.virtualTable.clearSelection()
      })
    },
    // 清空样本位置 按钮点击事件
    virtualClearLoc() {
      if (this.oldSelectTableCell && Object.keys(this.oldSelectTableCell).length > 0) {
        this.oldSelectTableCell.removeAttribute('style')
      }
      if (!this.virtualSelectSamples || this.virtualSelectSamples.length === 0) {
        this.$message('请选择要清空位置的样本')
        return false
      }
      this.virtualSelectTube = {}
      this.selectSamples.forEach((sample, index) => {
        this.virtualSelectSamples.forEach(item => {
          if (sample.sampBackupId === item.sampBackupId) {
            // 移出单据关联样本数组
            this.approveSamples.splice(this.approveSamples.indexOf(item), 1)
            item.sampLocation = ''
            this.selectSamples.splice(index, 1, item)
          }
        })
      })

      if (this.selectTubes && this.selectTubes.length > 0) {
        let tubesArray = this.selectTubes.reduce((prev, next) => {
          return prev.concat(next)
        })
        tubesArray.forEach((item, index) => {
          this.virtualSelectSamples.forEach(sample => {
            if (item.sample && item.sample.sampBackupId === sample.sampBackupId) {
              item.sample = undefined
              item.sampBackupId = undefined
              tubesArray.splice(index, 1, item)
            }
          })
        })
        this.convertArray(tubesArray)
      }

      let clearForm = {}
      clearForm.sampleBackups = this.virtualSelectSamples
      // 清空样本位置
      clearLocation(clearForm).then(response => {
        this.virtualSelectSamples = []
        this.$refs.virtualTable.clearSelection()
      })
    },
    // 删除冻存盒 按钮点击事件
    virtualDelBox() {
      this.selectTubes = []
      this.selectContainer = {}
      this.oldSelectTableCell = undefined
    },
    // 分配位置 单元格点击事件
    tableCellClick(row, column, cell, event) {
      let tableCell = row[parseInt(column.label) - 1]
      if (tableCell.tubeState === this.GLOBAL.TUBE.FORBIDDEN || tableCell.tubeState === this.GLOBAL.TUBE.DISABLE) { // tubeState === '2' tubeState === '1'
        return false
      }
      if (tableCell.sample && Object.keys(tableCell).length !== 0) {
        return false
      }
      if (this.oldSelectTableCell) {
        this.oldSelectTableCell.removeAttribute('style')
      }
      this.virtualSelectTube = tableCell
      cell.setAttribute('style', 'background:#409EFF')
      this.oldSelectTableCell = cell
    },
    // 容器树对话框确定
    confirmBoxSelect() {
      this.treeVisible = false
      if (this.selectContainer && this.selectContainer.containerId) {
        listTube(this.selectContainer.containerId).then(response => {
          const tubes = response.data
          this.convertArray(tubes)
        })
      } else {
        this.$message('请选择一个容器盒')
      }
    },
    // 容器树存储率颜色
    judgeColor(rate) {
      if (rate === 0) {
        return 'color: #909399'
      } else if (rate >= 0 && rate < 40) {
        return 'color: #409EFF'
      } else if (rate >= 40 && rate < 60) {
        return 'color: #67C23A'
      } else if (rate >= 60 && rate < 80) {
        return 'color: #E6A23C'
      } else if (rate >= 80 && rate <= 100) {
        return 'color: #F56C6C'
      }
    },
    // 一维数组转二维数组
    convertArray(tubes) {
      const row = this.selectContainer.boxRow
      const column = this.selectContainer.boxColumn
      this.selectTubes = []

      let itemArr = []
      tubes.forEach(tube => {
        // 如果小数组满了，创建一个新的小数组
        if (itemArr.length === column) {
          itemArr = []
        }
        // 如果小数组是空的，将小数组保存到大数组中
        if (itemArr.length === 0) {
          this.selectTubes.push(itemArr)
        }
        // 保存数据到小数组
        itemArr.push(tube)
      })
      this.tubeTableKey++
    },
    // 容器树对话框 取消按钮点击事件
    cancelBoxSelect() {
      this.treeVisible = false
    },
    // 容器树点击事件
    treeNodeClick(object, Node, element) {
      if (object.containerTypeCode === 'box') {
        this.highlightCurrent = true
        this.selectContainer = object
      } else {
        this.highlightCurrent = false
      }
    },
    /** 懒加载容器 列表 */
    loadLazyTree(node, resolve) {
      if (node.level === 0) {
        lazyTree(0).then(response => {
          resolve(response.data)
        })
      } else {
        lazyTree(node.data.containerId).then(response => {
          if (response.data && response.data.length > 0) {
            response.data.forEach(item => {
              if (item.containerTypeCode === 'box') {
                item.leaf = true
              }
            })
          }
          resolve(response.data)
        })
      }
    },
    // 待归还样本 多选框选中事件
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sampBackupId)
      this.selectSamples = selection
      this.multiple = !selection.length
    },
    // 样本所属人切换
    ownChange() {
      this.getList()
    },
    // 获取待归还样本
    getList() {
      this.loading = true
      listSample(this.queryParams).then(response => {
        this.sampleList = response.rows
        this.sampleList.map(item => {
          item.editShow = false
        })
        this.total = response.total
        this.loading = false
      })
    },
    /** 样本状态状态字典翻译 */
    sampStateFormat(row, column) {
      return this.selectDictLabel(this.sampStateOptions, row.sampState)
    },
    // 挑选样本
    handlePick() {
      this.open = true
    },
    // 批量移除
    handleRemove(row) {
      let sampBackups
      if (row.sampBackupId) {
        sampBackups = [row]
      } else {
        sampBackups = this.selectSamples
      }
      this.$confirm('是否确认移除选中的样本复份', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        sampBackups.forEach(item => {
          item.sampState = this.GLOBAL.SAMPLE.CLAIM //'5'
        })
        return updateSamples(sampBackups)
      }).then(() => {
        this.getList()
        this.msgSuccess('移除成功')
      })
    },
    // 编辑按钮点击事件
    handleEdit(index, row) {
      row.editShow = true
      this.$set(this.sampleList, index, row)
    },
    // 取消按钮点击事件
    handleCancel(index, row) {
      row.editShow = false
      this.$set(this.sampleList, index, row)
    },
    // 保存按钮点击事件
    handleSave(index, row) {
      if (!this.isNumber(row.sampQuantity)) {
        this.$message.error('请输入数字')
        return false
      }
      const str = new String(row.sampQuantity).replace('.', '')
      if (str.length > 6) {
        this.$message.error('输入的数字不能超过6位')
        return false
      }
      updateSample(row).then(res => {
        this.$message.success('保存成功')
        row.editShow = false
        this.$set(this.sampleList, index, row)
      })
    },
    // 选择样本对话框取消事件
    samplePickClose() {
      this.open = !this.open
    },
    // 样本挑选
    samplePickEvent(selection) {
      selection.forEach((item, index) => {
        item.sampState = this.GLOBAL.SAMPLE.TO_RETURN // '7'
      })
      updateSamples(selection).then(response => {
        this.open = !this.open
        selection.forEach((item, index) => {
          if (this.sampleList.indexOf(item) === -1) {
            item.editShow = false
            this.sampleList.push(item)
          }
        })
      })
    },
    // 扫码条码事件
    qrCodeChangeEvent(val) {
      if (!val || val === '') {
        return false
      }
      if (this.sampleList && this.sampleList.length > 0) {
        let exist = this.sampleList.every(item => item.qrCode === val)
        if (exist) {
          this.$message.error('该条码已扫描')
          return false
        }
      }
      let param = {}
      param.qrCode = val
      param.sampState = this.GLOBAL.SAMPLE.CLAIM // '5'
      let sample = {}
      getSampleByQrCode(param).then(response => {
        sample = response.data
        if (sample && Object.keys(sample).length !== 0) {
          sample.sampState = this.GLOBAL.SAMPLE.TO_RETURN // '7'
          return updateSample(sample)
        }
        return Promise.resolve()
      }).then(res => {
        sample.editShow = false
        this.sampleList.push(sample)
        this.qrCode = undefined
      })
    },
    // 表单重置
    reset() {

    },
    /**
     * 校验只要是数字（包含正负整数，0以及正负浮点数）就返回true
     **/
    isNumber(val) {
      debugger
      const regPos = /^[0-9]+\.?[0-9]*/ //判断是否是数字。
      if (regPos.test(val)) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>

<style scoped>
.box-card {
  margin-left: 7px;
  margin-right: 7px;
  min-height: 720px;
}

.bottom-btn {
  margin-right: 7px;
  margin-top: 15px;
  float: right
}

.steps {
  width: 80%;
  margin: 10px auto;
}

.table-icon {
  position: absolute;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom: 5%;
  width: 90%;
  height: 90%;
  object-fit: cover;
}

.table-icon-blur {
  position: absolute;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom: 5%;
  width: 90%;
  height: 90%;
  object-fit: cover;
  -webkit-filter: blur(2px);
}

/deep/ .el-input--small .el-input__inner {
  height: 29px;
  line-height: 29px;
}
</style>
